package com.yohann.algorithm.divideAndConquer;

/**
 * <p>
 * 汉诺塔问题
 * </p>
 *
 * @author Yohann
 * @since 2021/1/14 21:22
 */
public class HanoiTower {
    public static void main(String[] args) {
        hanoiTower(3, 'A', 'B', 'C');
    }

    /**
     * 汉诺塔
     */
    public static void hanoiTower(int num, char a, char b, char c) {
        if (num == 1) {
            System.out.println(String.format("1. %s -> %s", a, c));
        } else {
            //把上面的盘移动到b
            hanoiTower(num - 1, a, c, b);

            //把最下面的盘移动到c
            System.out.println(String.format("%s. %s -> %s", num, a, c));

            //b盘移动到c
            hanoiTower(num - 1, b, a, c);
        }
    }
}